package com.example.meitu.api.controller;

import com.example.meitu.api.common.Result;
import com.example.meitu.api.domain.MediaType;
import com.example.meitu.api.dto.ArticlesDTO;
import com.example.meitu.api.service.ArticleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    @GetMapping("/getArticles")
    public Result getArticles(@RequestParam(value = "accountId", required = false) Integer accountId,
                              @RequestParam(value = "subUnionId", required = false) Integer subUnionId,
                              @RequestParam(value = "platform", required = false) String platform,
                              @RequestParam(value = "startTime", required = true) Integer startTime,
                              @RequestParam(value = "endTime", required = true) Integer endTime){
        if (accountId != null) {
            List<ArticlesDTO> list = articleService.getArticles(accountId, startTime, endTime);
            return Result.success(list);
        } else {
            if (subUnionId == null) {
                return Result.fail(900001, "参数错误,accountId和subUnionId不能同时为空");
            } else {
                List<ArticlesDTO> list = articleService.getArticlesBySubUnionId(subUnionId, platform,startTime, endTime);
                return Result.success(list);
            }
        }
    }

}
